package dr.joketalker.controller;

import java.util.Observable;
import java.util.Observer;

import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ProgressBar;
import dr.joketalker.Application;
import dr.joketalker.R;
import dr.joketalker.Debug.MyDebug;

public class MyController extends Activity implements OnClickListener,Observer, OnItemClickListener {

	protected MyDebug myDebug;
	
	
	//protected static final String MY_BANNER_UNIT_ID = "a15026b311d7f7e";
	
	
	protected AdView adView = null;
	
	protected ProgressDialog progressDialog = null;
	
	@Override
	 public void onCreate(Bundle savedInstanceState) {
	 	
	        super.onCreate(savedInstanceState);
	        	         
	        progressDialog = new ProgressDialog(this);
	        myDebug = new MyDebug(this.getClass().getSimpleName());
	 }
	
	
	
	protected void init(){
		setLoading(false);
		
		
		adView = (AdView)findViewById(R.id.adView);
		
		if(adView == null){
			return;
		}
		
		AdRequest re = Application.GetInstance().getAdRequest();
		re.setTesting(true);
		
		adView.loadAd(re);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menu, menu);
	    return true;
	}
	
	protected void setLoading(boolean visible){
		ProgressBar pb = (ProgressBar)findViewById(R.id.pb0Progress);
		if(visible){
			pb.setVisibility(ProgressBar.VISIBLE);
		}else{
			pb.setVisibility(ProgressBar.INVISIBLE);
		}
	}
	
	 public void showProgressDialog()
     {
		 Resources res = getResources();

         progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
         progressDialog.setMessage(res.getString((R.string.loading)));
         progressDialog.setCancelable(false);

         progressDialog.show();
     }
	 
	 public void showFullLoading(){
		 showProgressDialog();
		 setLoading(true);
	 }
	 
	 public void hideFullLoading(){
		 hideProgressDialog();
		 setLoading(false);
	 }


     public void hideProgressDialog()
     {
         if (progressDialog != null && progressDialog.isShowing()) {

             progressDialog.hide();
         }
     }
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.itDebug:    Intent myIntent = new Intent(this, DebugController.class);
			startActivity(myIntent);	
		}
		 return true;	 
	}


	public void onClick(View v) {
	
		
	}


	public void update(Observable observable, Object data) {

		hideFullLoading();
		
	}


	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}
}
